/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/

#include <stdio.h>         /* Necesario para scanf*/
#include "system.h"        /* System funct/params, like osc/peripheral config */
#include "user.h"          /* User funct/params, such as InitApp */
#include <adc.h>
#include <delays.h>
#include "/XLCD/xlcd.h"

/******************************************************************************/
/* User Global Variable Declaration                                           */
/******************************************************************************/


/******************************************************************************/
/* Main Program                                                               */
/******************************************************************************/

void main(void)
{
    unsigned int ADC_value = 0;
    char str[30];

    /* Configure the oscillator for the device */
    ConfigureOscillator();

    /* Initialize I/O and Peripherals for application */
    InitApp();

    while(1)
    {
        ConvertADC();
        while(BusyADC());
        ADC_value = (unsigned int)ReadADC();

        /*Converts to decimal base.*/
        sprintf(str,(const MEM_MODEL rom char *)"Valor ADC: %u",ADC_value);
                
        /* Clear display */
        SendCommandXLCD(CLEAR);

        /* Set Display data ram address to first address in the 1st line*/
        while(BusyXLCD());
        SetDDRamAddr(0x80);
        putrsXLCD((const rom char *)"Juan Manuel gay!");

        /* Set Display data ram address to firt address in the 2nd line*/
        while(BusyXLCD());
        SetDDRamAddr(0xC0);
        
        /*Write string to LCD. String should be shorter than 16 bytes.
         * The max value is 1023 because ADC is 10 bits*/
        putsXLCD(str);

        SendCommandXLCD (CURSOR_OFF & BLINK_OFF);
        
        Delay10KTCYx(100);/* Delay for 1seg */

    }

}

